{% extends "WebMainSiteBundle:Course:layout.html.twig" %}
{% set title = "课程基本信息" %}
{% block title %}
    {{ title }}
{% endblock %}

{% block user_main %}
    <form class="form-horizontal" method="post" enctype="multipart/form-data">
        <div class="row">
            <div class="col-md-8">
                <div class="form-group">
                    <div class="col-md-3 text-right"><label class="control-label" for="title">课程标题:</label></div>
                    <div class="col-md-8">
                        <input
                                name="title"
                                id="title"
                                type="text"
                                class="form-control input-lg"
                                placeholder="请设置课程标题"
                                value="{% if course.title is defined %}{{ course.title }}{% endif %}"
                                />
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3 text-right"><label class="control-label" for="category">课程分类:</label></div>
                    <div class="col-md-8 sorts">
                        {#<select name="category"  class="form-control input-lg">#}
                            {#{% for c in courseCategory %}<option {% if course.category == c.id %} selected="selected" {% endif %} value="{{ c.id }}">{{ c.name }}</option>{% endfor %}#}
                        {#</select>#}
                        <select  class="form-control input-lg" id="Stage"></select>
                        <select  class="form-control input-lg" id="Grade" style="display: none;"></select>
                        <select  class="form-control input-lg" id="Term" style="display: none;"></select>
                        <select  class="form-control input-lg" id="Subject" style="display: none;"></select>
                        <select  class="form-control input-lg" id="Section" style="display: none;"></select>
                        <select  class="form-control input-lg" id="Point" style="display: none;"></select>
                        {#<select name="category"  class="form-control input-lg">#}
                        {#{% for c in courseCategory %}<option value="{{ c.id }}">{{ c.name }}</option>{% endfor %}#}
                        {#</select>#}
                        <input id="category" name="category" value="{% if Exam is defined %}{{ Exam.sort }}{% endif %}" type="hidden"/>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-3 text-right"><label class="control-label" for="info">课程简介:</label></div>
                    <div class="col-md-8">
                        <textarea  name="info" class="form-control" rows="11" id="info" placeholder="课程简介">{% if course.info is defined %}{{ course.info }}{% endif %}</textarea>
                    </div>
                </div>
                <p class="buttons-margin-horizontal">
                    <input type="submit" class="btn btn-theme btn-green" value="提交" />
                </p>
            </div>
        </div>
    </form>
{% endblock %}

{% block myJs %}
    {#{% include "AssetsUploadBundle:Uploadify:webPic.one.html.twig" %}#}
    {#<script>#}
    {#function rm(a){#}
    {#a.remove();#}
    {#}#}
    {#</script>#}
    {#---------------------------------------分类选择JS------------------------------------#}
    <script>
        function init(){
            $(".sorts").on("change","select", function () {
                var id = $(this).attr("id");
                var find = 0;
                for ( var i in choices ) {

                    if ( find ) {
                        $("#" + choices[i]).html("").hide();
                    }
                    if (choices[i] == id) {
                        find = 1;
                    }
                }

                var parentId = $(this).val();
                setDataById(parentId);
            });
        }
        function emptyData(target){

            $( "#" + target ).hide();
//            $("#" + target).html("");
        }
        function setData(target,id,cnName){
            var option = $('<option>');
            option.val(id).text(cnName);
            $( "#" + target ).append(option);
            $( "#" + target ).show();
        }
        function setDataById(id){
            var data = sorts[id];
//            data[i][0] = id
//            data[i][1] = name
//            data[i][2] = level
//            console.log(data);
            if(data){

                var start = 0;
                for(var i in data){
                    if (!start) {
                        setData(choices[data[i][2]],0,"请选择");
                        start = 1;
                    }
                    setData(choices[data[i][2]],data[i][0],data[i][1]);
                }
            }else {
                $("#category").val(id);
                console.log("目前试卷分类为:" + id);
            }
        }
        $(function () {
            setDataById("0");
            init();
            for( var n in link ){
                console.log(link[n])
                var id = link[n];
                var find = 0;
                for ( var i in choices ) {

                    if ( find ) {
                        $("#" + choices[i]).html("").hide();
                    }
                    if (choices[i] == id) {
                        find = 1;
                    }
                }

                var parentId = link[n];
                setDataById(parentId);

                $("select").find("option[value=" + link[n] + "]").attr("selected","selected");
            }
        });
    </script>
    <script>
        var sorts = {{ sorts|raw }};
        var choices = ["Stage","Grade","Term","Subject","Section","Point"];
                {% if Sort is defined %}var link = {{ Sort|raw }};{% endif %}

    </script>
    {#---------------------------------------分类选择JS------------------------------------#}
{% endblock %}